<template>
  <div class="container">
    <template>
      <!--顶部操作表单-->
      <el-form :inline="true" :model="listQuery" class="demo-form-inline">
        <el-form-item label="姓名">
          <el-input v-model="listQuery.name" placeholder="姓名"></el-input>
        </el-form-item>
        <el-form-item label="学号">
          <el-input v-model="listQuery.username" placeholder="学号"></el-input>
        </el-form-item>
        <el-form-item label="学院">
          <el-select v-model="listQuery.collegeId" :clearable="1===1" placeholder="请选择学院" @change="changeSelect">
            <el-option
              v-for="item in collegeOptions"
              :key="item.id"
              :label="item.collegeName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="班级">
          <el-select v-model="listQuery.classId" :clearable="1===1" placeholder="请选择班级">
            <el-option
              v-for="item in classOptions"
              :key="item.id"
              :label="item.className"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
      <!--请假列表-->
      <el-table
        :data="tableData"
        border
        v-loading="loading"
        style="width: 100%">
        <el-table-column
          prop="id"
          label="编号"
          width="180">
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="申请"
          width="180">
        </el-table-column>
        <el-table-column
          prop="username"
          label="用户名"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          label="姓名"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="reson"
          label="理由"
          width="250"
        >
        </el-table-column>
        <el-table-column
          prop="startTime"
          label="请假开始时间"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="startTime"
          label="请假结束时间"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="goArea"
          label="前往地点"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="backArea"
          label="返校地点"
          width="180"
        >
        </el-table-column>
        <el-table-column
          fixed="right"
          label="状态"
          width="180">
          <template slot-scope="scope">
              <span v-if="scope.row.agree==null&&scope.row.checked!=5">
            <el-button type="primary" size="mini" @click="toAgreeApply(scope.row)">同意</el-button>
              <el-button type="danger" size="mini" @click="toDisAgreeApply(scope.row)">不同意</el-button>
                </span>
            <el-tag type="success" v-else-if="scope.row.agree==1&&scope.row.checked==null">已同意</el-tag>
            <el-tag type="danger" v-else-if="scope.row.agree==0">不同意</el-tag>
            <el-tag type="danger" v-else-if="scope.row.checked==0" color="#b09ff5" style="color: white">不能到位置</el-tag>
            <el-tag type="danger" v-else-if="scope.row.checked==1" color="#b09ff5" style="color: white">已到位置</el-tag>
            <el-tag type="danger" v-else-if="scope.row.checked==4" color="#f5b800" style="color: white">无法返校</el-tag>
            <el-tag type="danger" v-else-if="scope.row.checked==5" color="#f55a00" style="color: white">已取消</el-tag>
            <el-tag v-else>已销假</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="180">
          <template slot-scope="scope">
            <el-button type="danger" icon="el-icon-delete" circle @click="handleDeleteClick(scope.row)"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="listQuery.page"
          :page-sizes="[5, 10, 15]"
          :page-size="listQuery.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </template>
  </div>
</template>

<script>
  import {getStudentList, addStudent} from "../../api/student";
  import {geClassdropDownList, getCollegedropDownList, getRoledropDownList} from "../../api/common";
  import {delHolidayApply, getHolidayList, toAgree} from "../../api/holiday";

  export default {
    name: "",
    data() {
      return {
        loading: false,
        tableData: [],
        addDialogFormVisible: false,
        formLabelWidth: '120px',
        total: 0,
        addForm: {
          id: '',
          username: '',
          createTime: '',
          name: '',
          reson: '',
          goArea: '',
          startTime: '',
          endTime: '',
          area: '',
          collegeId: '',
          typeForEdit: '',//添加是add，修改是edit
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
        forAgreeApply: {
          id: Number,
          agree: Number,
        },
        classOptions: [],
        collegeOptions: [],
        roleOptions: [],
        listQuery: {
          page: 1,
          size: 5,
          collegeId: '',
          classId: '',
          name: '',
          username: ''
        }
      }
    },
    methods: {
      //删除请假
      handleDeleteClick(param){
        this.loading=true
        delHolidayApply({id:param.id}).then(res=>{
          this.$message.success("删除成功")
          this.getHolidayList()
          this.loading=false
        }).catch(err=>{
          this.loading=false
        })
      },
      //同意请假
      toAgreeApply(params) {
        this.loading=true
        console.log(params.id)
        this.forAgreeApply.id = params.id
        this.forAgreeApply.agree = 1
        toAgree(this.forAgreeApply).then(res => {
          console.log(res)
          if (res.code == 20000) {
            this.$message.success("操作成功");
            this.getHolidayList();
          } else {

          }
          this.loading=false
        }).catch(err => {
          this.loading=false
        })
      },
      //不同意请假
      toDisAgreeApply(params) {
        this.loading=true
        console.log(params.id)
        this.forAgreeApply.id = params.id
        this.forAgreeApply.agree = 0
        toAgree(this.forAgreeApply).then(res => {
          console.log(res)
          if (res.code == 20000) {
            this.$message.success("操作成功");
            this.getHolidayList();
          } else {

          }
          this.loading=false
        }).catch(err => {
          this.loading=false
        })
      },
      // 获取请假列表
      getHolidayList() {
        this.loading = true
        getHolidayList(this.listQuery).then(res => {
          this.tableData = res.data.pageList
          this.total = res.data.total
          console.log(res)
          this.loading = false
        }).catch(err=>{
          this.loading = false
        })

      },
      //获取学院列表
      getdropDownListForCollege() {
        getCollegedropDownList(1484744242220589057)
          .then(res => {
            console.log(res)
            this.collegeOptions = res.data
          })
      },
      //获取班级列表
      getdropDownListForClass() {
        geClassdropDownList(this.listQuery.collegeId)
          .then(res => {
            console.log(res)
            this.classOptions = res.data
          })
      },
      //获取权限列表
      getDropdownListForRole() {
        getRoledropDownList().then(res => {
          this.roleOptions = res.data
        })
      },
      //分页相关
      handleSizeChange(val) {
        this.listQuery.size = val
        this.getHolidayList()
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.listQuery.page = val
        this.getHolidayList()
        console.log(`当前页: ${val}`);
      },
      //点击查询
      onSubmit() {
        this.getHolidayList()
      },
      changeSelect() {
        this.getdropDownListForClass()
      },
    },
    created() {
      this.getHolidayList()
      this.getdropDownListForCollege()
    }
  }
</script>

<style scoped>
  .demo-form-inline {
    margin-top: 20px;
    margin-left: 10px;
  }
</style>
